/**
 * loading控制器
 * 注册loadGroup事件
 */
class LoadController extends Controller {
    protected loadingView: LoadingView;
    /** 子类可修改默认装载的位图资源 */
    protected defaultGroupName: string = "preload";

    public constructor() {
        super();
    }
    
    /**
     * 初始化控制器, 具体操作在子类里实现
     */
    protected init(): void {
        //如果未setLoadingView则取通用view
        if(this.loadingView == null){
            this.loadingView = this.commonViewManager.loadingView;
        }
        if(this.root.numElements >1 && this.root.getChildAt(0) == this.loadingView){
            Log.d("has loadingView");
        }else{
            this.root.addChild(this.loadingView);
        }
        //load资源
        ResManager.get.loadGroup(this.defaultGroupName,this.onResourceLoadComplete,this.onResourceProgress,this);
    }
     
    public setLoadingView(loadingView: LoadingView):void{
        this.loadingView = loadingView;
    }
    
    protected onResourceLoadComplete(groupName:string):void{
        this.root.removeChild(this.loadingView);
        //启动splash页 
        this.dispatch(CMDEvent.OPEN_SPLASH);  
    } 
    
    protected onResourceProgress(progress: number,total: number): void{
        this.loadingView.setProgress(progress,total);
    } 
     
    
    
}
